package 力扣;

/**
 * @author yyq
 * @create 2022-04-08 8:50
 */
public class leetcode226 {
    public TreeNode invertTree(TreeNode root) {
        if(root==null) return root;
        preOrderInvert(root);
        return root;
    }

    private void preOrderInvert(TreeNode root) {
        if(root==null) return;
        TreeNode temp=root.left;
        root.left=root.right;
        root.right=temp;

        if(root.left!=null) preOrderInvert(root.left);
        if(root.right!=null) preOrderInvert(root.right);
    }
}
